import Vue from 'vue'
import VueRouter from 'vue-router'
//import Login from '../components/Login.vue'
const Login=()=>import (/*webpackChunkName:"login_home_welcome"*/'../components/Login.vue')
//import Home from '../components/Home.vue'
const Home=()=>import (/*webpackChunkName:"login_home_welcome"*/'../components/Home.vue')
//import Welcome from '../components/Welcome.vue'
const Welcome=()=>import (/*webpackChunkName:"login_home_welcome"*/'../components/Welcome.vue')
//import users from '../components/user/users.vue'
const users=()=>import (/*webpackChunkName:"users"*/'../components/user/users.vue')
//import rights from '../components/rights/rights.vue'
const rights=()=>import (/*webpackChunkName:"right_roles"*/'../components/rights/rights.vue')
//import roles from '../components/rights/roles.vue'
const roles=()=>import (/*webpackChunkName:"right_roles"*/'../components/rights/roles.vue')
//import cate from '../components/shop/cate.vue'
const cate=()=>import (/*webpackChunkName:"cate_params_list"*/'../components/shop/cate.vue')
//import params from '../components/shop/params.vue'
const params=()=>import (/*webpackChunkName:"cate_params_list"*/'../components/shop/params.vue')
//import list from '../components/shop/list.vue'
const list=()=>import (/*webpackChunkName:"cate_params_list"*/'../components/shop/list.vue')
//import add from '../components/shop/add'
const add=()=>import (/*webpackChunkName:"add"*/'../components/shop/add')
//import order from '../components/order/order.vue'
const order=()=>import (/*webpackChunkName:"order"*/'../components/order/order.vue')
//import report from '../components/report/report.vue'
const report=()=>import (/*webpackChunkName:"order"*/'../components/report/report.vue')
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/login',
    component: Login
  }, 
  {
    path: '/Home',
    component: Home,
    redirect: '/welcome',
    children: [{
        path: '/welcome',
        component: Welcome
      },
      {
        path: '/0-0',
        component: users
      },
      {
        path: '/1-0',
        component: roles
      },
      {
        path: '/1-1',
        component: rights
      },
      {
        path: '/2-0',
        component: list
      }, {
        path: '/2-1',
        component: params
      }, {
        path: '/2-2',
        component: cate
      },
      {
        path: '/shop/add',
        component: add
      },{
        path:'/3-0',
        component:order
      },
      {
        path:'/4-0',
        component:report
      }
    ]
  }
]

const router = new VueRouter({
  routes
})

const Foo=()=>import (/*webpackChunkName:""*/'./')

router.beforeEach((to, from, next) => {
  //to将要访问的路径，from 从什么地方来的，next表示放行
  if (to.path === '/login') {
    return next();
  }
  const tokenstr = window.sessionStorage.getItem('token');
  if (!tokenstr) return next('/login');
  next();
})
export default router
